home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / ENTRPRIS / APE / AEQUEUE / QUEUEMGR.CLS < prev   
Encoding:
Visual Basic class definition  |  1996-12-23  |  30.0 KB  |  699 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "QueueMgr"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = True
  10. Attribute VB_Description = "Provides an interface for AEQueueMgr to be configured and administrated."
  11. Option Explicit
  12. '-------------------------------------------------------------------------
  13. 'This public multi-use class provides the OLE interface for the APE Manager
  14. 'or another application designed to be the Manager
  15. '-------------------------------------------------------------------------
  16.  
  17. '***********************
  18. 'Public Properties
  19. '***********************
  20. Public Property Let MaxQueueSize(ByVal lMax As Long)
  21. Attribute MaxQueueSize.VB_Description = "Sets or returns the value that controls the size of the Queue that causes Service Requests to be rejected."
  22.     '-------------------------------------------------------------------------
  23.     'Purpose:   MaxQueueSize property determines the maximum amount
  24.     '           of ServiceRequests that will be allowed to back up
  25.     'Effects:   [glMax] becomes value of parameter
  26.     '-------------------------------------------------------------------------
  27.     glMaxQueueSize = lMax
  28. End Property
  29.  
  30. Public Property Get MaxQueueSize() As Long
  31.     MaxQueueSize = glMaxQueueSize
  32. End Property
  33.  
  34. Public Property Let ShowQueue(ByVal bShow As Boolean)
  35. Attribute ShowQueue.VB_Description = "Determines whether the AEQueueMgr shows a form."
  36.     '-------------------------------------------------------------------------
  37.     'Purpose:   Show property determines whether or not a form
  38.     '           is displayed while QueueMgr is loaded
  39.     'Effects:   [gbShow] becomes value of parameter
  40.     '           If parameter is true frmQueueMgr is show, else form
  41.     '           is Unloaded.
  42.     '-------------------------------------------------------------------------
  43.     If Not gbShow = bShow Then
  44.         gbShow = bShow
  45.         If bShow Then
  46.             With frmQueueMgr
  47.                 .Show
  48.                 .lblCount.Caption = glAddCallCount
  49.                 .lblPeak.Caption = glPeakQueueSize
  50.                 .lblQueue.Caption = gcQueue.Count
  51.                 .lblWorkerCount.Caption = gcWorkers.Count
  52.             End With
  53.         Else
  54.             Unload frmQueueMgr
  55.         End If
  56.     End If
  57.     
  58. End Property
  59.  
  60. Public Property Get ShowQueue() As Boolean
  61.     ShowQueue = gbShow
  62.     
  63. End Property
  64.  
  65. Public Property Let LogQueue(ByVal bLog As Boolean)
  66. Attribute LogQueue.VB_Description = "Determines if the AEQueueMgr logs its events and errors to the AELogger.Logger object."
  67.     '-------------------------------------------------------------------------
  68.     'Purpose:   If log is true create logger class object and log Services
  69.     'Effects:   [gbLog] becomes value of parameter
  70.     '           [goLogger] is set to a new AELogger.Logger object if parameter
  71.     '                      is true.  If false goLogger is destroyed
  72.     '-------------------------------------------------------------------------
  73.     On Error GoTo LogQueueError
  74.     If Not gbLog = bLog Then
  75.         gbLog = bLog
  76.         If bLog Then
  77.             Set goLogger = New aelogger.Logger
  78.         Else
  79.             Set goLogger = Nothing
  80.         End If
  81.     End If
  82.     Exit Property
  83. LogQueueError:
  84.     Select Case Err.Number
  85.         Case ERR_CANT_FIND_KEY_IN_REGISTRY
  86.             'AEInstancer.Instancer is a work around for error
  87.             '-2147221166 which occurrs every time a client
  88.             'object creates an instance of a remote server,
  89.             'destroys it, registers it local, and tries to
  90.             'create a local instance.  The client can not
  91.             'create an object registered locally after it created
  92.             'an instance while it was registered remotely
  93.             'until it shuts down and restarts.  Therefore,
  94.             'it works to call another process to create the
  95.             'local instance and pass it back.
  96.             Dim oInstancer As AEInstancer.Instancer
  97.             Set oInstancer = New AEInstancer.Instancer
  98.             Set goLogger = oInstancer.Object("AELogger.Logger")
  99.             Set oInstancer = Nothing
  100.             Resume Next
  101.         Case Else
  102.             Err.Raise Err.Number, Err.Source, Err.Description
  103.     End Select
  104. End Property
  105.  
  106. Public Property Get LogQueue() As Boolean
  107.     LogQueue = gbLog
  108. End Property
  109.  
  110. '********************
  111. 'Worker Properties
  112. '********************
  113. Public Property Let LogWorkers(ByVal bLog As Boolean)
  114. Attribute LogWorkers.VB_Description = "Sets the value that is used to set the Log property of AEWorker.Worker objects."
  115.     '-------------------------------------------------------------------------
  116.     'Purpose:   To set the Log property of all the Workers
  117.     'Effects:
  118.     '   [gbLogWorkers]
  119.     '           becomes equal to the passed parameter
  120.     'Assumes:   There is a collection of one or more valid Worker objects
  121.     '-------------------------------------------------------------------------
  122.     'If the property setting actually
  123.     'changes the current property pass
  124.     'the property change to all the Workers
  125.     Dim oWork As clsWorker
  126.     If Not bLog = gbLogWorkers Then
  127.         For Each oWork In gcWorkers
  128.             oWork.Worker.Log = bLog
  129.         Next oWork
  130.         gbLogWorkers = bLog
  131.     End If
  132. End Property
  133.  
  134. Public Property Get LogWorkers() As Boolean
  135.     LogWorkers = gbLogWorkers
  136. End Property
  137.  
  138. Public Property Let PersistentServices(ByVal bPersistent As Boolean)
  139. Attribute PersistentServices.VB_Description = "Sets the value that is used to set the PersistentServices property of AEWorker.Worker objects."
  140.     '-------------------------------------------------------------------------
  141.     'Purpose:   To set the PersistentServices property of all the Workers
  142.     'Effects:
  143.     '   [gbPersistentServices]
  144.     '           becomes equal to the passed parameter
  145.     'Assumes:   There is a collection of one or more valid Worker objects
  146.     '-------------------------------------------------------------------------
  147.     'If the property setting actually
  148.     'changes the current property pass
  149.     'the property change to all the Workers
  150.     Dim oWork As clsWorker
  151.     If Not bPersistent = gbPersistentServices Then
  152.         For Each oWork In gcWorkers
  153.             oWork.Worker.PersistentServices = bPersistent
  154.         Next oWork
  155.         gbPersistentServices = bPersistent
  156.     End If
  157. End Property
  158.     
  159. Public Property Get PersistentServices() As Boolean
  160.     PersistentServices = gbPersistentServices
  161. End Property
  162.  
  163. Public Property Let EarlyBindServices(ByVal bEarlyBind As Boolean)
  164. Attribute EarlyBindServices.VB_Description = "Sets the value that is used to set the EarlyBindServices property of AEWorker.Worker objects."
  165.     '-------------------------------------------------------------------------
  166.     'Purpose:   To set the EarlyBindServices property of all the Workers
  167.     'Effects:
  168.     '   [gbEarlyBindServices]
  169.     '           becomes equal to the passed parameter
  170.     'Assumes:   There is a collection of one or more valid Worker objects
  171.     '-------------------------------------------------------------------------
  172.     'If the property setting actually
  173.     'changes the current property pass
  174.     'the property change to all the Workers
  175.     Dim oWork As clsWorker
  176.     If Not bEarlyBind = gbEarlyBindServices Then
  177.         For Each oWork In gcWorkers
  178.             oWork.Worker.EarlyBindServices = bEarlyBind
  179.         Next oWork
  180.         gbEarlyBindServices = bEarlyBind
  181.     End If
  182. End Property
  183.  
  184. Public Property Get EarlyBindServices() As Boolean
  185.     EarlyBindServices = gbEarlyBindServices
  186. End Property
  187.  
  188. '********************
  189. 'Expediter Properties
  190. '********************
  191.  
  192. Public Property Let ShowExpediter(ByVal bShow As Boolean)
  193. Attribute ShowExpediter.VB_Description = "Sets the Show property of the AEExpediter.Expediter object."
  194.     '-------------------------------------------------------------------------
  195.     'Purpose:   To set the Show property of the Expediter
  196.     'Effects:
  197.     '   [gbShowExpediter]
  198.     '           becomes equal to the passed parameter
  199.     'Assumes:
  200.     '   [goExpediter]
  201.     '           Is a valid AEExpediter.Expediter object
  202.     '-------------------------------------------------------------------------
  203.     'If the property setting actually
  204.     'changes the current property pass
  205.     'the property change to the expediter
  206.     If Not bShow = gbShowExpediter Then
  207.         goExpediter.Show = bShow
  208.         gbShowExpediter = bShow
  209.     End If
  210. End Property
  211.  
  212. Public Property Get ShowExpediter() As Boolean
  213.     ShowExpediter = gbShowExpediter
  214. End Property
  215.  
  216. Public Property Let LogExpediter(ByVal bLog As Boolean)
  217. Attribute LogExpediter.VB_Description = "Set the Log property of the AEExpediter.Expediter object."
  218.     '-------------------------------------------------------------------------
  219.     'Purpose:   To set the Log property of the Expediter
  220.     'Effects:
  221.     '   [gbLogExpediter]
  222.     '           becomes equal to the passed parameter
  223.     'Assumes:
  224.     '   [goExpediter]
  225.     '           Is a valid AEExpediter.Expediter object
  226.     '-------------------------------------------------------------------------
  227.     'If the property setting actually
  228.     'changes the current property pass
  229.     'the property change to the expediter
  230.     If Not bLog = gbLogExpediter Then
  231.         goExpediter.Log = bLog
  232.         gbLogExpediter = bLog
  233.     End If
  234. End Property
  235.  
  236. Public Property Get LogExpediter() As Boolean
  237.     LogExpediter = gbLogExpediter
  238. End Property
  239.  
  240. '****************************
  241. 'Public Methods
  242. '****************************
  243.  
  244. Public Sub SetProperties(ByVal bShow As Boolean, Optional ByVal bLog As Variant)
  245. Attribute SetProperties.VB_Description = "Sets all of the AEQueueMgr.QueueMgr related properties in one method call."
  246.     '-------------------------------------------------------------------------
  247.     'Purpose:   To set the QueueMgr properties in one method call
  248.     'Effects:   Sets the following properties to parameter values
  249.     '           ShowQueue, LogQueue, WorkerQuantity
  250.     '-------------------------------------------------------------------------
  251.     With Me
  252.         .ShowQueue = bShow
  253.         If Not IsMissing(bLog) Then .LogQueue = bLog
  254.     End With
  255. End Sub
  256.  
  257. Public Sub SetWorkerProperties(ByVal bLog As Boolean, Optional ByVal bEarlyBindServices As Variant, _
  258.         Optional ByVal bPersistentServices As Variant)
  259. Attribute SetWorkerProperties.VB_Description = "Sets all of the AEWorker.Worker related properties on one method call."
  260.     '-------------------------------------------------------------------------
  261.     'Purpose:   To set the Worker properties in one method call
  262.     'Effects:   Sets the following properties to parameter values
  263.     '           ShowWorkers, LogWorkers, EarlyBindServices, PersistentServices
  264.     '-------------------------------------------------------------------------
  265.     Dim oWork As clsWorker
  266.     gbLogWorkers = bLog
  267.     If Not IsMissing(bEarlyBindServices) Then gbEarlyBindServices = bEarlyBindServices
  268.     If Not IsMissing(bPersistentServices) Then PersistentServices = bPersistentServices
  269.     For Each oWork In gcWorkers
  270.         oWork.Worker.SetProperties gbLogWorkers, gbEarlyBindServices, gbPersistentServices
  271.     Next oWork
  272. End Sub
  273.  
  274. Public Sub SetExpediterProperties(ByVal bShow As Boolean, Optional ByVal bLog As Variant)
  275. Attribute SetExpediterProperties.VB_Description = "Sets all of the AEExpediter.Expediter related properties in one method call."
  276.     '-------------------------------------------------------------------------
  277.     'Purpose:   To set the Expediter properties in one method call
  278.     'Effects:   Sets the following properties to parameter values
  279.     '           ShowExpediter, LogExpediter
  280.     '-------------------------------------------------------------------------
  281.     gbShowExpediter = bShow
  282.     If Not IsMissing(bLog) Then gbLogExpediter = bLog
  283.     goExpediter.SetProperties gbShowExpediter, gbLogExpediter
  284.     
  285. End Sub
  286.  
  287. Public Sub SetConnectionProperties(ByVal bUseDCOM As Boolean, Optional ByVal sProtocol As Variant, _
  288.                                     Optional ByVal lAuthentication As Variant)
  289. Attribute SetConnectionProperties.VB_Description = "Sets the connection parameters to be used when creating remote AEWorker.Worker objects."
  290.     '-------------------------------------------------------------------------
  291.     'Purpose:   To set the Connection Settings that the QueueMgr will use
  292.     '           to connect to remote Workers
  293.     'In:
  294.     '   [bUseDCOM]
  295.     '           If true workers will be created using DCOM instead of
  296.     '           Remote Automation.
  297.     '   [sProtocol]
  298.     '           Protocol sequence to use when connecting to remote objects
  299.     '   [lAuthentication]
  300.     '           Authentication level to use
  301.     'Effects:
  302.     '   [gbUseDCOM]
  303.     '           becomes equal to bUseDCOM parameter
  304.     '   [gsProtocol]
  305.     '           becomes equal to sProtocol parameter
  306.     '   [glAuthentication]
  307.     '           becomes equal to lAuthentication parameter
  308.     '-------------------------------------------------------------------------
  309.     Dim iVarType As Integer     'Variant type code of lAuthentication
  310.     gbUseDCOM = bUseDCOM
  311.     If Not IsMissing(sProtocol) Then
  312.         If VarType(sProtocol) = vbString Then gsProtocol = sProtocol
  313.     End If
  314.     If Not IsMissing(lAuthentication) Then
  315.         iVarType = VarType(lAuthentication)
  316.         If iVarType = vbLong Or iVarType = vbInteger Or iVarType = vbDouble Or iVarType = vbSingle Then
  317.             glAuthentication = lAuthentication
  318.         End If
  319.     End If
  320. End Sub
  321.  
  322. Public Function CreateWorkers(ByVal bRemoteWorkers As Boolean, Optional ByVal lWorkerQuantity As Variant, _
  323.                                     Optional ByVal lWorkersPerMachine As Variant, Optional ByVal vaMachineList As Variant, _
  324.                                     Optional ByVal bUseLocalMachine As Variant) As String
  325. Attribute CreateWorkers.VB_Description = "Creates AEWorker.Worker objects.  Returns a string that describes any errors that occurred."
  326.     '-------------------------------------------------------------------------
  327.     'Purpose:   Sets the settings for remote workers.  These settings provide
  328.     '           The QueueMgr the information needed to create Workers on several
  329.     '           remote machines rather than just the local one.
  330.     'IN:
  331.     '   [bRemoteWorkers]
  332.     '           If true, the QueueMgr will create Workers on remote machines.
  333.     '           If false, the QueueMgr will only create Workers on the local machine.
  334.     '   [lWorkerQuantity]
  335.     '           The total number of Workers to be created.
  336.     '   [lWorkersPerMachine]
  337.     '           A variant long specifing the maximum allowed number of Workers
  338.     '           to create on a single machine.
  339.     '   [vaMachineList]
  340.     '           A string array, providing the list of machine names
  341.     '           to create the workers on.  If this is not a valid
  342.     '           array of strings it will be treated like no machine
  343.     '           names were specified
  344.     '   [bUseLocalMachine]
  345.     '           If true, include local machine in list of remote machine names
  346.     'Return:    String to display to user and print to log file.  Will contain
  347.     '           any error information and the total number of workers created
  348.     '-------------------------------------------------------------------------
  349.                                     
  350.     Static stbUseDCOM As Boolean     'Last DCom automation setting used
  351.     Static stsProtocol As String     'Last Automation protocol setting used
  352.     Static stlAuthentication As Long 'Last Automation Authentication setting used
  353.     Dim sResult As String   'Result of SetWorkersOnMachine function
  354.     Dim sErrors As String   'String with error descriptions to return for
  355.                             'display to user
  356.     Dim oWorkerMachine As clsWorkerMachines 'Object in gcWorkerMachines collection
  357.                                             'that stores how many workers are instanciated
  358.                                             'on a particular machine
  359.     Dim lUB As Long         'Ubound of passed array
  360.     Dim bListExists As Boolean  'True if a array of machine names exists
  361.     Dim bInList As Boolean  'If true the Machine Name is in the passed array
  362.     Dim i As Integer        'For...Next loop counter
  363.     Dim lAdd As Long        'Number of Workers to add on machine
  364.     Dim lNumOnMach As Long  'Number of workers on a machine
  365.     Dim iVarType As Integer 'Variant data type of a parameter
  366.     
  367.     On Error GoTo CreateWorkersError
  368.     
  369.     'Validate the parameters
  370.     'validate lWorkerQuantity
  371.     iVarType = VarType(lWorkerQuantity)
  372.     If Not (iVarType = vbLong Or iVarType = vbInteger Or iVarType = vbSingle Or iVarType = vbDouble) Then
  373.         Err.Raise giINVALID_PARAMETER, , LoadResString(giINVALID_PARAMETER)
  374.     ElseIf lWorkerQuantity <= 0 Then
  375.         'Make sure at least one worker is created
  376.         lWorkerQuantity = 1
  377.     End If
  378.     If bRemoteWorkers Then
  379.         'validate vaMachineList
  380.         iVarType = VarType(vaMachineList)
  381.         If (iVarType = vbArray + vbString) Or (iVarType = vbArray + vbVariant) Then
  382.             On Error Resume Next
  383.             lUB = UBound(vaMachineList)
  384.             If Err.Number <> ERR_SUBSCRIPT_OUT_OF_RANGE Then
  385.                 bListExists = True
  386.             End If
  387.             On Error GoTo CreateWorkersError
  388.         End If
  389.         'validate lworkerspermachine
  390.         iVarType = VarType(lWorkersPerMachine)
  391.         If Not (iVarType = vbLong Or iVarType = vbInteger Or iVarType = vbSingle Or iVarType = vbDouble) Then
  392.             Err.Raise giINVALID_PARAMETER, , LoadResString(giINVALID_PARAMETER)
  393.         ElseIf lWorkersPerMachine <= 0 Then
  394.             lWorkersPerMachine = 1
  395.         End If
  396.         'validate bUseLocalMachine
  397.         On Error Resume Next
  398.         bUseLocalMachine = CBool(bUseLocalMachine)
  399.         If Err.Number = ERR_TYPE_MISMATCH Then
  400.             On Error GoTo CreateWorkersError
  401.             Err.Raise giINVALID_PARAMETER, , LoadResString(giINVALID_PARAMETER)
  402.         Else
  403.             On Error GoTo CreateWorkersError
  404.         End If
  405.     End If
  406.     
  407.     'First destroy all workers that can not be used any more
  408.     'If connection settings have been changed or if bRemoteWorkers
  409.     'is false all Workers on remote machines must be destroyed
  410.     If (Not bRemoteWorkers) Or (stbUseDCOM <> gbUseDCOM) Or (stsProtocol <> gsProtocol) Or (stlAuthentication <> glAuthentication) Then
  411.         'Reset the Last Connection setting static variables
  412.         stbUseDCOM = gbUseDCOM
  413.         stsProtocol = gsProtocol
  414.         stlAuthentication = glAuthentication
  415.         'Destroy all remote Workers
  416.         For Each oWorkerMachine In gcWorkerMachines
  417.             If oWorkerMachine.Remote Then
  418.                 sResult = SetWorkersOnMachine(True, oWorkerMachine.MachineName, 0)
  419.                 sErrors = sErrors & sResult
  420.             End If
  421.         Next
  422.     Else
  423.         'If we did not destroy all workers on remote machines
  424.         'destroy workers that are on machines that are not
  425.         'in the passed list of remote worker machines
  426.         
  427.         'Check if the machine names currently in gcWorkerMachines
  428.         'are in the passed array
  429.         For Each oWorkerMachine In gcWorkerMachines
  430.             If oWorkerMachine.Remote Then
  431.                 bInList = False
  432.                 If bListExists Then
  433.                     For i = 0 To lUB
  434.                         If vaMachineList(i) = oWorkerMachine.MachineName Then
  435.                             bInList = True
  436.                             Exit For
  437.                         End If
  438.                     Next
  439.                 End If
  440.                 If Not bInList Then
  441.                     sResult = SetWorkersOnMachine(True, oWorkerMachine.MachineName, 0)
  442.                     sErrors = sErrors & sResult
  443.                 End If
  444.             End If
  445.         Next
  446.     End If
  447.     
  448.     'See if Workers on local machine need destroyed
  449.     If bRemoteWorkers Then
  450.         If Not bUseLocalMachine Then
  451.             sResult = SetWorkersOnMachine(False, "", 0)
  452.             sErrors = sErrors & sResult
  453.         End If
  454.     End If
  455.     
  456.     'Create Workers
  457.     If Not bRemoteWorkers Then
  458.         'Just create all workers on local machine
  459.         sResult = SetWorkersOnMachine(False, "", CLng(lWorkerQuantity))
  460.         sErrors = sErrors & sResult
  461.     Else
  462.         'Now loop through machine name list and add workers
  463.         'to each machine until giWorkerCount equals
  464.         'lWorkerQuantity or the end of the machine list is
  465.         'reached
  466.         If giWorkerCount <= lWorkerQuantity Then
  467.             'First create workers on local machine
  468.             If bUseLocalMachine Then
  469.                 'Get the number of workers currently on this machine
  470.                 lNumOnMach = gcWorkerMachines.Item(1).WorkerKeys.Count
  471.                 'Set number of Workers to be on current machine
  472.                 lAdd = lWorkersPerMachine
  473.                 If lAdd > (lWorkerQuantity + lNumOnMach) - giWorkerCount Then lAdd = (lWorkerQuantity + lNumOnMach) - giWorkerCount
  474.                 sResult = SetWorkersOnMachine(False, "", lAdd)
  475.                 sErrors = sErrors & sResult
  476.             End If
  477.             
  478.             If bListExists Then
  479.                 Do Until (i > lUB Or giWorkerCount = lWorkerQuantity)
  480.                     On Error Resume Next
  481.                     'Get the number of workers currently on this machine
  482.                     Set oWorkerMachine = gcWorkerMachines.Item(vaMachineList(i))
  483.                     If Err.Number = ERR_INVALID_PROCEDURE_CALL Then
  484.                         lNumOnMach = 0
  485.                     Else
  486.                         lNumOnMach = oWorkerMachine.WorkerKeys.Count
  487.                     End If
  488.                     On Error GoTo CreateWorkersError
  489.                     'Set number of Workers to be on current machine
  490.                     lAdd = lWorkersPerMachine
  491.                     If lAdd > (lWorkerQuantity + lNumOnMach) - giWorkerCount Then lAdd = (lWorkerQuantity + lNumOnMach) - giWorkerCount
  492.                     sResult = SetWorkersOnMachine(True, CStr(vaMachineList(i)), lAdd)
  493.                     sErrors = sErrors & sResult
  494.                     i = i + 1
  495.                 Loop
  496.             End If
  497.         Else
  498.             'There may be too many workers, so destroy workers to
  499.             'make the right count
  500.             If bListExists Then
  501.                 i = lUB
  502.                 Do While i >= 0
  503.                     On Error Resume Next
  504.                     'Get the number of workers currently on this machine
  505.                     Set oWorkerMachine = gcWorkerMachines.Item(vaMachineList(i))
  506.                     If Err.Number = ERR_INVALID_PROCEDURE_CALL Then
  507.                         lNumOnMach = 0
  508.                     Else
  509.                         lNumOnMach = oWorkerMachine.WorkerKeys.Count
  510.                     End If
  511.                     On Error GoTo CreateWorkersError
  512.                     If lNumOnMach > 0 Then
  513.                         lAdd = 0
  514.                         If lNumOnMach > (giWorkerCount - lWorkerQuantity) Then lAdd = lNumOnMach - (giWorkerCount - lWorkerQuantity)
  515.                         sResult = SetWorkersOnMachine(True, CStr(vaMachineList(i)), lAdd)
  516.                         sErrors = sErrors & sResult
  517.                     End If
  518.                     i = i - 1
  519.                 Loop
  520.             End If
  521.             
  522.             'if there are still too many workers
  523.             'reduce the number of workers on the local machine
  524.             If giWorkerCount > lWorkerQuantity Then
  525.                 lNumOnMach = gcWorkerMachines.Item(1).WorkerKeys.Count
  526.                 lAdd = 0
  527.                 If lNumOnMach > (giWorkerCount - lWorkerQuantity) Then lAdd = lNumOnMach - (giWorkerCount - lWorkerQuantity)
  528.                 sResult = SetWorkersOnMachine(False, "", lAdd)
  529.                 sErrors = sErrors & sResult
  530.             End If
  531.         End If
  532.     End If
  533.     
  534.     'Check if any workers were created and raise error if none were created
  535.     If giWorkerCount < lWorkerQuantity Then
  536.         If giWorkerCount = 0 Then
  537.             Err.Raise giNO_WORKERS_CREATED, , sErrors & vbCrLf & LoadResString(giNO_WORKERS_CREATED)
  538.         Else
  539.             sErrors = sErrors & vbCrLf & ReplaceString(LoadResString(giONLY_N_WORKERS_CREATED), gsNUMBER_TOKEN, CStr(giWorkerCount))
  540.         End If
  541.     Else
  542.         sErrors = sErrors & vbCrLf & LoadResString(giALL_WORKERS_CREATED)
  543.     End If
  544.     
  545.     CreateWorkers = sErrors
  546.     Exit Function
  547. CreateWorkersError:
  548.     Select Case Err.Number
  549.         Case Is > giERROR_THRESHOLD
  550.             Err.Raise Err.Number + vbObjectError, Err.Source, Err.Description
  551.         Case Else
  552.             Err.Raise Err.Number, Err.Source, Err.Description
  553.     End Select
  554. End Function
  555.  
  556. Public Function GetRemoteLoggerCollection() As Collection
  557. Attribute GetRemoteLoggerCollection.VB_Description = "Returns a collection of remote AELogger.Logger objects that were created by remote AEWorker.Worker objects."
  558.     '-------------------------------------------------------------------------
  559.     'Purpose:   Returnse the collection of loggers created on the same
  560.     '           machines as remote Workers
  561.     'Assumes:
  562.     '   [gcWorkerMachines]
  563.     '           a valid collection of clsWorkerMachines object
  564.     '   [clsWorkerMachines]
  565.     '           If .Remote is true .WorkerKeys.Count is > 0
  566.     '-------------------------------------------------------------------------
  567.     Dim cRemoteLoggers As Collection        'Collection to return
  568.     Dim oWorkerMachine As clsWorkerMachines 'Object representing each Worker machine
  569.     Dim oLogger As aelogger.Logger          'Valid logger object or nothing
  570.     
  571.     Set cRemoteLoggers = New Collection
  572.     
  573.     For Each oWorkerMachine In gcWorkerMachines
  574.         With oWorkerMachine
  575.             If .Remote Then
  576.                 Set oLogger = gcWorkers.Item(CStr(.WorkerKeys(1))).Worker.GetLogger
  577.                 If Not oLogger Is Nothing Then
  578.                     cRemoteLoggers.Add oLogger
  579.                 End If
  580.             End If
  581.         End With
  582.     Next
  583.     
  584.     If cRemoteLoggers.Count = 0 Then Set cRemoteLoggers = Nothing
  585.     Set GetRemoteLoggerCollection = cRemoteLoggers
  586. End Function
  587.  
  588. Public Sub LoadServiceObject(ByVal ServiceLibClass As String)
  589. Attribute LoadServiceObject.VB_Description = "Causes all created AEWorker.Worker objects to create an object whose ProgID matches ServiceLibClass."
  590.     '-------------------------------------------------------------------------
  591.     'Purpose:   Purpose is to call LoadServiceObject method in each
  592.     '           instanciated worker.  It is ignored if gbPeristentServices
  593.     '           is false
  594.     'Assumes:
  595.     '   [gcWorkers]
  596.     '           Is a collection of valid AEWorker.Worker objects
  597.     '-------------------------------------------------------------------------
  598.     Dim oWork As clsWorker
  599.     If gbPersistentServices Then
  600.         For Each oWork In gcWorkers
  601.             oWork.Worker.LoadServiceObject ServiceLibClass
  602.         Next oWork
  603.     End If
  604. End Sub
  605.  
  606. Public Sub StopTest()
  607. Attribute StopTest.VB_Description = "Causes the AEQueueMgr to stop processing Service Requests and to empty its queue."
  608.     '-------------------------------------------------------------------------
  609.     'Purpose:   Stops all Queue Managers processes
  610.     'Effects:
  611.     '           May call StopQueue
  612.     '   [gbStopTest]
  613.     '           Becomes true
  614.     '-------------------------------------------------------------------------
  615.     'Call this to halt the Queue Manager and the Expediter
  616.     goExpediter.StopTest
  617.     gbStopTest = True
  618.     If Not gbBusyAdding And Not gbBusyGetServiceRequest Then StopQueue
  619.     Exit Sub
  620. End Sub
  621.  
  622. Public Sub StartTest()
  623. Attribute StartTest.VB_Description = "Prepares the AEQueueMgr to process Service Requests after StopTest has been called."
  624.     '-------------------------------------------------------------------------
  625.     'Purpose:   Call this to allow processing of Services after calling StopTest
  626.     'Effects:
  627.     '           Resets U/I to look like QueueMgr just started
  628.     '   [gbStopTest]
  629.     '           Becomes False
  630.     '-------------------------------------------------------------------------
  631.     
  632.     Dim oWork As clsWorker
  633.     Dim iRetry As Integer
  634.     
  635.     On Error GoTo StartTestError
  636.     
  637.     'Reset stats
  638.     gbStopTest = False
  639.     
  640.     With goExpediter
  641.         iRetry = 0
  642.         '.QueueMgrRef must be set before StartTest is called
  643.         Set .QueueMgrRef = New clsQueueDelegator
  644.         .StartTest
  645.     End With
  646.     If gbShow Then
  647.         DisplayStatus ""
  648.         glAddCallCount = 0
  649.         glPeakQueueSize = 0
  650.         With frmQueueMgr
  651.             .lblCount.Caption = 0
  652.             .lblPeak.Caption = 0
  653.             .lblQueue.Caption = 0
  654.             .lblWorkerCount.Caption = gcWorkers.Count
  655.             .lblCount.Refresh
  656.             .lblPeak.Refresh
  657.             .lblQueue.Refresh
  658.             .lblWorkerCount.Refresh
  659.         End With
  660.     End If
  661.     Exit Sub
  662. StartTestError:
  663.     Select Case Err.Number
  664.         Case RPC_E_CALL_REJECTED
  665.             'Collision error, the OLE server is busy
  666.             Dim il As Integer
  667.             Dim ir As Integer
  668.             'First check for stop test
  669.             If iRetry < giMAX_ALLOWED_RETRIES Then
  670.                 iRetry = iRetry + 1
  671.                 ir = Int((giRETRY_WAIT_MAX - giRETRY_WAIT_MIN + 1) * Rnd + giRETRY_WAIT_MIN)
  672.                 For il = 0 To ir
  673.                     DoEvents
  674.                 Next il
  675.                 LogEvent giCALL_REJECTED_RETRY, 0
  676.                 Resume
  677.             Else
  678.                 'We reached our max retries
  679.                 LogError Err, -1
  680.                 Resume Next
  681.             End If
  682.         Case Else
  683.             Err.Raise Err.Number, Err.Source, Err.Description
  684.     End Select
  685. End Sub
  686.  
  687. '********************
  688. 'Private Procedures
  689. '********************
  690.  
  691. Private Sub Class_Initialize()
  692.     CountInitialize
  693. End Sub
  694.     
  695. Private Sub Class_Terminate()
  696.     CountTerminate
  697. End Sub
  698.  
  699.